export default{
    //json格式化
    copyObject:function (ob) {
        return JSON.parse(JSON.stringify(ob))
    },
    //时间格式化
    timeSToHMS:function (time) {
        let h = Math.floor(time / 3600) < 10 ? '0'+Math.floor(time / 3600) : Math.floor(time / 3600);
        let m = Math.floor((time / 60 % 60)) < 10 ? '0' + Math.floor((time / 60 % 60)) : Math.floor((time / 60 % 60));
        let s = Math.floor((time % 60)) < 10 ? '0' + Math.floor((time % 60)) : Math.floor((time % 60));
        return h + ":" + m + ":" + s
    },
    iniMenuPermissions(data){
        let parentName = []
        let arr1=[]
        for(let i=0;i<data.length;i++){
            data[i]['label'] = data[i].name
            let a = {
                title: data[i].name,
                value: data[i].id,
                key: data[i].id,
                children:[]
            }
            arr1.push(a)
            for(let s =0;s<data[i].children.length;s++){
              if(data[i].children[s].children.length>0){
                data[i].children[s]['label'] = data[i].children[s].name
                let b = {
                    title: data[i].children[s].name,
                    value: data[i].children[s].id,
                    key: data[i].children[s].id,
                    children:[]
                }
                arr1[i].children.push(b)
                if(data[i].children[s].children.length>0){
                    for(let c=0;c<data[i].children[s].children.length;c++){
                        data[i].children[s].children[c]['label'] = data[i].children[s].children[c].name
                        let cc = {
                            title: data[i].children[s].children[c].name,
                            value: data[i].children[s].children[c].id,
                            key: data[i].children[s].children[c].id,
                            children:[]
                        }
                        arr1[i].children[s].children.push(cc)
                    }
                }else{
                    data[i].children[s].children[c]['label'] = data[i].children[s].children[c].name
                    let cc = {
                            title: data[i].children[s].children[c].name,
                            value: data[i].children[s].children[c].id,
                            key: data[i].children[s].children[c].id,
                            children:[]
                        }
                        arr1[i].children[s].children.push(cc)
                }
                
              }else{
                data[i].children[s]['label'] = data[i].children[s].name
                let b = {
                    title: data[i].children[s].name,
                    value: data[i].children[s].id,
                    key: data[i].children[s].id,
                    children:[]
                }
                arr1[i].children.push(b)
              }
              
            }
        }
        parentName= arr1
        console.log(parentName)
        return parentName
    },
    iniMenuMenu(data){
        let parentName = []
        let arr1=[]
        for(let i=0;i<data.length;i++){
            data[i]['label'] = data[i].title
            data[i]['children'] = data[i].childrens
            let a = {
                title: data[i].title,
                value: data[i].id,
                key: data[i].id,
                children:[]
            }
            arr1.push(a)
            for(let s =0;s<data[i].childrens.length;s++){
              if(data[i].childrens[s].childrens.length>0){
                data[i].childrens[s]['label'] = data[i].childrens[s].title
                data[i].childrens[s]['children'] = data[i].childrens[s].childrens
                let b = {
                    title: data[i].childrens[s].title,
                    value: data[i].childrens[s].id,
                    key: data[i].childrens[s].id,
                    children:[]
                }
                arr1[i].children.push(b)
                if(data[i].childrens[s].childrens.length>0){
                 
                    for(let c=0;c<data[i].childrens[s].childrens.length;c++){
                      // console.log(data[i].childrens[s].childrens[c])
                      if(data[i].childrens[s].childrens[c].childrens.length>0){
                        // console.log(data[i].childrens[s].childrens[c])
                        data[i].childrens[s].childrens[c]['label'] = data[i].childrens[s].childrens[c].title
                        data[i].childrens[s].childrens[c]['children'] = data[i].childrens[s].childrens[c].childrens
                        let cc = {
                            title: data[i].childrens[s].childrens[c].title,
                            value: data[i].childrens[s].childrens[c].id,
                            key: data[i].childrens[s].childrens[c].id,
                            children:[]
                        }
                        arr1[i].children[s].children.push(cc)

                        for(let d=0;d<data[i].childrens[s].childrens[c].childrens.length;d++){
                          // console.log(data[i].childrens[s].childrens[c].childrens[d])
                          data[i].childrens[s].childrens[c].childrens[d]['label'] = data[i].childrens[s].childrens[c].childrens[d].title
                          data[i].childrens[s].childrens[c].childrens[d]['children'] = data[i].childrens[s].childrens[c].childrens[d].childrens
                          let cc = {
                              title: data[i].childrens[s].childrens[c].childrens[d].title,
                              value: data[i].childrens[s].childrens[c].childrens[d].id,
                              key: data[i].childrens[s].childrens[c].childrens[d].id,
                              children:[]
                          }
                          // console.log(cc)
                          // console.log(data[i].childrens[s].childrens[c])
                          arr1[i].children[s].children[c].children.push(cc)
                        }
                      }else{
                        data[i].childrens[s].childrens[c]['label'] = data[i].childrens[s].childrens[c].title
                        data[i].childrens[s].childrens[c]['children'] = data[i].childrens[s].childrens[c].childrens
                        let cc = {
                            title: data[i].childrens[s].childrens[c].title,
                            value: data[i].childrens[s].childrens[c].id,
                            key: data[i].childrens[s].childrens[c].id,
                            children:[]
                        }
                        arr1[i].children[s].children.push(cc)
                      }
                        
                    }
                }else{
                    data[i].childrens[s].childrens[c]['label'] = data[i].childrens[s].childrens[c].title
                    data[i].childrens[s].childrens[c]['children'] = data[i].childrens[s].childrens[c].childrens
                    let cc = {
                            title: data[i].childrens[s].childrens[c].title,
                            value: data[i].childrens[s].childrens[c].id,
                            key: data[i].childrens[s].childrens[c].id,
                            children:[]
                        }
                        arr1[i].children[s].children.push(cc)
                }
                
              }else{
                data[i].childrens[s]['label'] = data[i].childrens[s].title
                data[i].childrens[s]['children'] = data[i].childrens[s].childrens
                let b = {
                    title: data[i].childrens[s].title,
                    value: data[i].childrens[s].id,
                    key: data[i].childrens[s].id,
                    children:[]
                }
                arr1[i].children.push(b)
              }
              
            }
        }
        parentName= arr1
        console.log(parentName)
        return parentName
    },

    formatDateTime(date, format) {
      // console.log(date)
        const o = {
          'M+': date.getMonth() + 1, // 月份
          'd+': date.getDate(), // 日
          'h+': date.getHours() % 12 === 0 ? 12 : date.getHours() % 12, // 小时
          'H+': date.getHours(), // 小时
          'm+': date.getMinutes(), // 分
          's+': date.getSeconds(), // 秒
          'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
          S: date.getMilliseconds(), // 毫秒
          a: date.getHours() < 12 ? '上午' : '下午', // 上午/下午
          A: date.getHours() < 12 ? 'AM' : 'PM', // AM/PM
        };
        if (/(y+)/.test(format)) {
          format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (let k in o) {
          if (new RegExp('(' + k + ')').test(format)) {
            format = format.replace(
              RegExp.$1,
              RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
            );
          }
        }
        return format;
    },
    getTimeDifference(time1,time2){
      if(!time1){
        return ""
      }
      if(!time2){
        return ""
      }
      const date1 = new Date(time1); // 将时间字符串解析成Date对象
      const date2 = new Date(time2);
      const difference = Math.abs(date1 - date2); // 计算绝对值，避免负数
      const hours = Math.floor(difference / (1000 * 60 * 60)); // 计算小时数
      const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60)); // 计算分钟数
      const seconds = Math.floor((difference % (1000 * 60)) / 1000); // 计算秒数
      // return { hours, minutes, seconds }; // 返回相差的小时、分钟和秒数
      return hours+'小时'+ minutes+'分钟'+ seconds+'秒' ; // 返回相差的小时、分钟和秒数
    },
    // timeSS(timestamp){
    //   timestamp = Number(timestamp)
    //   // const hours = Math.floor(timestamp / 3600*1000); // 转换为小时
    //   // const minutes = Math.floor((timestamp % 3600) / 60*1000); // 转换为分钟
    //   // const seconds = timestamp % 60; // 转换为秒钟
    //   console.log(timestamp)
    //   const hour_ms = 60 * 60 * 1000; //一小时等于的毫秒数 
    //   const min_ms = 60 * 1000; // 一分钟等于的毫秒数 
    //   const ss_ms = 1000; //一秒等于的毫秒数 
    //   const hours = parseInt(timestamp / hour_ms); //获取小时部分
    //   const minutes = parseInt(timestamp % hour_ms / min_ms); //获取分钟部分 
    //   const seconds = parseInt(timestamp % ss_ms / 1000); //获取秒数

    //   console.log(hours,minutes,seconds)
    //   const formattedTime = hours + ':' + ("0" + minutes).slice(-2) + ':' + ("0" + seconds).slice(-2);
    //   // console.log(formattedTime)
    //   return formattedTime;
    // },
    timeSS(seconds) {
      seconds = Number(seconds)
      const hours = Math.floor(seconds / 3600);
      const minutes = Math.floor((seconds % 3600) / 60);
      const remainingSeconds = seconds % 60;
  
      const formattedHours = String(hours).padStart(2, '0');
      const formattedMinutes = String(minutes).padStart(2, '0');
      const formattedSeconds = String(remainingSeconds).padStart(2, '0');
  
      return formattedHours + ':' + formattedMinutes + ':' + formattedSeconds;
  }
}